﻿using CommonServiceLocator;
using Jn698._45GWTool.ViewModels.Controls;
using Jn698._45GWTool.ViewModels.Controls.DataControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Jn698._45GWTool.Controls
{
    /// <summary>
    /// MeterArchivesControl.xaml 的交互逻辑
    /// </summary>
    public partial class MeterArchivesControl : UserControl
    {
        MeterArchivesViewModel viewModel = ServiceLocator.Current.GetInstance<MeterArchivesViewModel>();
        public MeterArchivesControl()
        {
            InitializeComponent();
            this.DataContext = viewModel;
        }

        private void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            var Check = (sender as CheckBox);
            if (int.TryParse(Check.Uid, out int CUID))
            {
                //全选
                if (CUID == -1)
                {
                    foreach (var item in viewModel.MeterInfoList)
                        item.IsSelect = true;
                    Check.Uid = "-2";
                    return;
                }
                //全否选
                if (CUID == -2)
                {
                    foreach (var item in viewModel.MeterInfoList)
                        item.IsSelect = false;
                    Check.Uid = "-1";
                    return;
                }
            }
            else
            {
                int index = (int)viewModel.SelectedMeterInfo;
                bool result = (bool)viewModel.MeterInfoList[(int)viewModel.SelectedMeterInfo].IsSelect ? false : true;
                viewModel.MeterInfoList[index].IsSelect = result;
            }
        }
    }
}
